// JavaScript Document
$(
	function(){
		$(".p2_sortul li").click(function(){
			$(this).attr('class','p2_sortli02');
			$(this).siblings().attr('class','p2_sortli01');
			//$('#metadata_'+$(this).attr('parentid')).val($(this).attr('selfid'));
			//formatFormData();
			if($(this).attr('selfid') != null){		//xiaoyuemian: metadata list
			    $('#metadata_'+$(this).attr('parentid')).val($(this).attr('selfid'));
			    formatFormData();
			}
			else{										//xiaoyuemian: category list
				window.location = '/c/search/' + $(this).attr('cid') + '/';
			}
		});
//		$('#sortby_price_select').change(function(){formatFormData()});
//		$('#sortby_created_select').change(function(){formatFormData()});
	}
);

function jampToCertanPage()
{
	formatFormData($('#pageNumberToJump').val());
}

function formatFormData(int_page){
    var str_filter = '/' + $('#categoryid').val();
    var str_tmpFilter = '';
    if(int_page)
        str_tmpFilter += '/page/' + int_page;
    //获取filter
    $("#sortForm li[class='p2_sortli02'][selfid!='0']").each(function(){
    	if(this.getAttribute('selfid') != null){
    	str_tmpFilter += '/' + this.getAttribute('parentid') + '/' + this.getAttribute('selfid');
    	}
    });
    //获取sort
    if($('#sortby_price_select').get()[0]){
        if($('#sortby_price_select').val()!='0'){
        	var src = "http://i.vmserver/t/default_zh_cn/image/p2_searchdiv1.gif";
        	$(".p2 img").attr("src",src);
            str_tmpFilter += '/price/' + $('#sortby_price_select').val();
        }
    }
    if($('#sortby_created_select').get()[0]){
        if($('#sortby_created_select').val()!='0'){
        	var src = "http://i.vmserver/t/default_zh_cn/image/p2_searchdiv1.gif";
        	$(".p2 img").attr("src",src);
            str_tmpFilter += '/created/' + $('#sortby_created_select').val();
        }
    } 
    
    str_filter += str_tmpFilter;
    
    $.ajax({
        type: 'post',
        url: '/a/categorysearch' + str_filter,
        dataType: "html",
        async: false,  //false is synchronization , true is asynchronism
        success: function(data){
            $('#searchResultBlock').replaceWith(data);
            //window.location += str_tmpFilter;
            return true;
        },
        error: function(){
            result = false;
        }
    });
}

$(function(){
	$(".p2 img").click(
	function(){
		var src = "http://i.vmserver/t/default_zh_cn/image/p2_searchdiv1.gif";
		$(this).attr("src",src);
	});
});
